/**
 * 
 */
package org.dragonfire.irc.server;

import java.net.ServerSocket;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;

import org.dragonfire.irc.messages.Message;

/**
 * @author Darth Android
 * @date Oct 27, 2007
 */
public class IRCServer {

	HashSet<ServerConnection> links = new HashSet<ServerConnection>();

	HashMap<String, ServerConnection> serverRoutingCache = new HashMap<String, ServerConnection>();

	private HashMap<Integer, ServerSocket> sockets = new HashMap<Integer, ServerSocket>();

	private HashSet<ClientConnection> clients = new HashSet<ClientConnection>();

	private Queue<Message> messageQueue = new LinkedList<Message>();

	public void bindPort(int port) {
		if (sockets.get(port) != null)
			return;
		try {
			ServerSocket ss = new ServerSocket(port);
			sockets.put(port, ss);
		} catch (Exception e) {
			throw new RuntimeException(e.getMessage(), e);
		}
	}

	public void rebuildServerCache() {
		synchronized (serverRoutingCache) {
			serverRoutingCache.clear();
			synchronized (links) {
				for (ServerConnection sc : links) {
					for (String server : sc.getServerLinks()) {

					}
				}
			}
		}
	}

}
